package net.huashitong.oversee.web;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.JqGrid;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.Project.responseModel.MailListDataModel;
import net.huashitong.Project.responseModel.NodeNewschedulesDataModel;
import net.huashitong.Project.service.ExportService;
import net.huashitong.node.filter.NodeNewschedulesFilter;
import net.huashitong.node.service.NodeNewschedulesService;
import net.huashitong.oversee.filter.CoordinateFilter;
import net.huashitong.oversee.filter.SupervisionTaskFilter;
import net.huashitong.oversee.service.CoordinateService;
import net.huashitong.oversee.service.SupervisionTaskService;
import net.huashitong.user.databean.BnpUserDatabean;
import net.huashitong.user.entity.BnpUser;
import net.huashitong.user.filter.BnpUserFilter;
import net.huashitong.user.service.BnpUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.util.WebUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/reportForm1")
public class ReportForm1Ctrl extends JsonBaseController {
    @Override
    protected String getView(String s) {
        return "/modules/reportForm1/" + s;
    }

    @Autowired
    private BnpUserService bnpUserService;
    @Autowired
    private ExportService exportService;

    @RequestMapping(method = RequestMethod.GET)
    public String initPage(HttpServletRequest request, Model model) {
        model.addAttribute("leftType", "报表模块");
        BnpUser bnpUser = (BnpUser) WebUtils.getSessionAttribute(request, "user");
        if (ObjectUtils.isBlank(bnpUser)) {
            return "/modules/login/login";
        }
        int myTaskNum = (int) WebUtils.getSessionAttribute(request, "myTaskNum");
        int quetionNum = (int) WebUtils.getSessionAttribute(request, "quetionNum");
        model.addAttribute("myTaskNum", myTaskNum);
        model.addAttribute("quetionNum", quetionNum);

        int myTackTaskNum = (int) WebUtils.getSessionAttribute(request, "myTackTaskNum");
        model.addAttribute("myTackTaskNum", myTackTaskNum);

        //待办任务个数
        int nodeCount = (int) WebUtils.getSessionAttribute(request, "nodeCount");
        model.addAttribute("nodeCount", nodeCount);

        model.addAttribute("user",bnpUser);
        return getView("query");
    }


    //初始化数据
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST)
    public JqGrid query(@ModelAttribute BnpUserFilter filter) {
        List<MailListDataModel> list = exportService.queryMailListData(filter);
        /*for(MailListDataModel mail : list){
            //峰会时期手机号码加密
            if(mail.getPhone().length()==11){
                String newPhone = mail.getPhone().substring(0,3)+"****"+mail.getPhone().substring(7,11);
                mail.setPhone(newPhone);
            }
        }*/
        return coverJqGrid(filter, list);
    }

    @RequestMapping("/filter")
    public String filter(@ModelAttribute BnpUserFilter filter, Model model) {
        model.addAttribute("userList", filter);
        //查询所有单位
        List<String> branchs = bnpUserService.queryAllBranchs();
        model.addAttribute("branchs", branchs);
        return getView("filter");
    }

    @RequestMapping("/formHead")
    public String showHead(@ModelAttribute NodeNewschedulesFilter filter, Model model) {
        model.addAttribute("taskjob", filter);
        return getView("formHead");
    }

    @RequestMapping(value = "getFeedBackPage", method = RequestMethod.GET)
    public String getFeedBackPage(HttpServletRequest request, Model model) {
        model.addAttribute("leftType", "意见反馈");
        return "/modules/reportForm/feedback";
    }
}
